<?php
/**
 * Created by PhpStorm
 * User: Jhinwy
 * Date: 7/25/24
 * Time: 10:22 AM
 */

namespace app\adminapi\controller\media;


use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\media\MediaAuthLists;
use app\adminapi\logic\media\MediaAuthLogic;


class MediaAuthController extends BaseAdminController
{


    /**
     * 获取列表
     *
     * @return \think\response\Json
     */
    public function lists()
    {
        return $this->dataLists(new MediaAuthLists());
    }


    /**
     * 获取所有的媒体授权应用
     *
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function all()
    {
        return $this->data(MediaAuthLogic::all());
    }


    /**
     * 获取媒体授权信息字段
     *
     * @return \think\response\Json
     */
    public function getMediaType()
    {
        return $this->data(MediaAuthLogic::getMediaType());
    }


    /**
     * 添加媒体授权应用
     *
     * @return \think\response\Json
     */
    public function add()
    {
        $params             = $this->request->post();
        $params['admin_id'] = $this->adminId;
        MediaAuthLogic::add($params);

        return $this->success('添加成功', [], 1, 1);
    }


    /**
     * 编辑媒体授权应用
     *
     * @return \think\response\Json
     */
    public function edit()
    {
        $params = $this->request->post();
        return MediaAuthLogic::edit($params) ?
            $this->success('编辑成功', [], 1, 1) : $this->fail('编辑失败');
    }
}
